<?php
set_time_limit(0); //防止执行超时
ob_end_clean();   //清空并关闭输出缓冲区

if(!isset($_GET["id"])){
    echo "pls input id!";
    return;
}

include("base_function.php");
include("base/db.php");

function analyse(&$times)
{
    $m["Jan"]=1;
    $m["Feb"]=2;
    $m["Mar"]=3;
    $m["Apr"]=4;
    $m["May"]=5;
    $m["Jun"]=6;
    $m["Jul"]=7;
    $m["Aug"]=8;
    $m["Sep"]=9;
    $m["Oct"]=10;
    $m["Nov"]=11;
    $m["Dec"]=12;
    
    foreach($times as $time){
        $reg = '|([\d]*?)-([A-Za-z]*?)-([\d]*?) ([\d]*?):([\d]*?):([\d]*?) |';
        $ret = preg_match ($reg,$time["time"],$out);
        if(!$ret)
            continue;
        // 月份转换
        $out[2] = $m[$out[2]];
        $data = mktime($out[4],$out[5],$out[6],$out[2],$out[1],$out[3]);
        $data = getdate($data);
        
        if(!isset($hour[$out[4]]))
            $hour[$out[4]] = 0;
        $hour[$out[4]]++;
        if(!isset($weekday[$data["weekday"]]))
            $weekday[$data["weekday"]] = 0;
        $weekday[$data["weekday"]] ++;
        if(!isset($weekday_detail[$data["weekday"]][$out[4]]))
            $weekday_detail[$data["weekday"]][$out[4]] = 0;
        $weekday_detail[$data["weekday"]][$out[4]] ++;
        ksort($weekday_detail[$data["weekday"]]);
    }
    ksort($hour);
    print_r($hour);
    print_r($weekday);
    print_r($weekday_detail);
    
}
function doit()
{
    open_db();
    $times = query_db("select time from pm_sale_time where catalog_id =".$_GET["id"]);
    analyse($times);
    close_db();
    return;
}

doit();
echo "ok";

?>
